package com.example.myandroidapp1;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.example.myandroidapp1.dto.ImageLoader;
import com.example.myandroidapp1.dto.MyGallery;

public class ImageAdapter extends BaseAdapter {
	private Context context;
	private View gridView;

	// private List<String> imageList;
	private MyGallery myGallery;

	/*public ImageAdapter(Context context, List<String> imageList) {
		this.context = context;
		this.imageList = imageList;
	}
*/
	public ImageAdapter(GridViewActivity context, MyGallery myGallery) {
		this.context = context;
		this.myGallery = myGallery;
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if (convertView == null) {

			gridView = new View(context);
			gridView = inflater.inflate(R.layout.gridviewdata, null);
			// initialize();
			TextView hiddenTextView = (TextView) gridView.findViewById(R.id.tvGridItemHidden);
			ImageView imageView = (ImageView) gridView.findViewById(R.id.grid_item_image);
			ProgressBar progressBar = (ProgressBar) gridView.findViewById(R.id.pbImage);

			// textView.setText(mobileValues[position]);
			new ImageLoader(imageView, progressBar, hiddenTextView).execute(myGallery.getImageList().get(position).getThumbnail());

		} else {
			gridView = (View) convertView;
		}

		return gridView;
	}

	@Override
	public int getCount() {
		return myGallery.getImageList().size();
	}

	@Override
	public Object getItem(int position) {
		return null;
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

}